
$(document).ready(function () {
	//初始化文件输入框
	initMySummernote("content");
    var id=getvl("id");
	if(id!=null && id!=""){
		getData(id);
	}
});


/**
 * 提交
 */
function release() {
	var id=getvl("id");
	var content = $('#content').summernote('code');
	var title = $('#title').val();
	var type=$("#type").val();
    $.ajax({
        url:  urlcore + "/api/msgModel/addOrupdate",
       		type: "post",
	       	data: JSON.stringify({
	            "id": id,
	            "content": content,
	          	"type":type,
	          	"title":title
	        }),
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
                if (data.success == true) {
	                   location.reload();
                } else {
                    alert(data.msg);
                }

        },
        error: function() {
            alert("error");
        }

    });
}


/**
 * 获取协议数据
 */
function getData(id){
	   $.ajax({
        url:  urlcore + "/api/msgModel/selectOne?id="+id,
       		type: "get",
	       	data:{},
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
                if (data.success == true) {
	                   $("#type option[value='"+data.data.type+"']").attr("selected", true);
	                   $("#title").val(data.data.title);
	                   $('#content').summernote('code',data.data.content)
	                   
                } else {
                    alert(data.msg);
                }

        },
        error: function() {
            alert("error");
        }

    });
	
}


